﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Film.Common;

namespace Film.Repository
{
    public partial class tblAgeRepository : Repository<tblAge>
    {
        public tblAge GetByAgeID(int ageID)
        {
            return dataContext.tblAges.FirstOrDefault(x => x.AgeID == ageID);
        }

        public List<tblAge> Filter(string keyWord, int start, int limit, out int count)
        {
            keyWord = UtilString.XacDinhNguyenAm(keyWord);
            var result = (from ds in dataContext.tblAges
                          where (keyWord == "" ||
                          (keyWord != "" && (System.Data.Linq.SqlClient.SqlMethods.Like(ds.AgeName, "%" + keyWord + "%"))))
                          select ds);

            count = result.Count();
            return result.Skip(start).Take(limit).ToList();
        }

        public int GetNextID()
        {
            tblAge entity = dataContext.tblAges.OrderByDescending(x => x.AgeID).FirstOrDefault();
            if (entity != null)
            {
                return entity.AgeID + 1;
            }
            return 1;
        }
    }
}
